/*
Autor: Alexander Savochkin, 2010
New BSD License
*/

#include <boost/test/unit_test.hpp>

#include "Config.h"

using namespace SRCLF;
using namespace SRCLF::Config;

bool readConfigTest(Configuration& config, const string& config_filename)
{
	config.readConfigFile( config_filename );
	const Section& sec = config.getSection( Section::resource, "base_com_io" );

	if ( sec.getName() != "base_com_io" )
		return false;

	if ( sec.getType() != Section::resource )
		return false;

	if ( sec.getScalarByKey("baud_rate") != "115200" )
		return false;

	if ( sec.getScalarByKey("parity") != "n" )
		return false;	

	const Section& sec2 = config.getSection( Section::server, "main" );

	const vector<string>& va = sec2.getAllValuesByKey("interface");
	if ( va.size() != 2 )
		return false;

	return true;
}

bool inheritanceConfigTest(Configuration& config)
{
	config.processInheritace();

	//Check if inheritance is done correctlu
	const Section s = config.getSection(Section::resource, "com1_io");

	if (s.getScalarByKey("baud_rate") != "115200")
		return false;

	if (s.getScalarByKey("parity") != "n")
		return false;

	if (s.getScalarByKey("file_name") != "com1" )
		return false;

	return true;
}

BOOST_AUTO_TEST_CASE( config_parser_test )
{
	
	Configuration config1;
	const char* config1_filename = "test1.config";

	BOOST_CHECK( readConfigTest(config1, config1_filename) );
	BOOST_CHECK( inheritanceConfigTest(config1) );
}

